//
//  BrightnessControl.m
//  LabanBrowser
//
//  Created by hoangtx on 4/18/13.
//  Copyright (c) 2013 Simon Peter Grätzer. All rights reserved.
//

#import "BrightnessControl.h"
#import "MyUtilities.h"

@implementation BrightnessControl

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/
-(void)relocalize{
    self.brightnessLB.text = [MyUtilities getLocalizeStringFromTag:@"MenuBrightness"];
}

-(void)initialize{
    self.alpha = 0;
    double currentBrightnessLevel = [[UIScreen mainScreen]brightness];
    [self.brightnessSlider setValue:currentBrightnessLevel];
    self.brightnessLB.text = [MyUtilities getLocalizeStringFromTag:@"MenuBrightness"];
    //[backgroundView setImage:[[UIImage imageNamed:@"bg_browser_titlebar_urlbar_nor.png"] stretchableImageWithLeftCapWidth:45 topCapHeight:25]];
    [self.boundingIMV setImage:[[UIImage imageNamed:@"bg_browser_titlebar_urlbar_nor.png"] stretchableImageWithLeftCapWidth:45 topCapHeight:25]];
}


- (IBAction)closeAction:(id)sender {
    [self needToShow:NO];
}

- (IBAction)brightnessChanged:(id)sender {
    [[UIScreen mainScreen] setBrightness:self.brightnessSlider.value];
    
    //[[UIScreen mainScreen] brightness
}

-(void)needToShow:(BOOL)_need{
    double alphaToAnimateTo;
    if(_need){
        alphaToAnimateTo = 1;
    }else{
        alphaToAnimateTo = 0;
    }
    
    [UIView animateWithDuration:0.25f
                          delay:0
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         self.alpha = alphaToAnimateTo;
    } completion:^(BOOL finished) {
        
    }];
}

@end
